{% include "header.html" %}

<div class="container">
    <div class="box box-primary">
        <div class="box-header">
            <div class="text-center">
                <span class="h-title">个人主页</span>
            </div>
        </div>
        <div class="box-body">
            <div class="row">
                <div class="col-lg-6 col-xs-12">
                    {% if data and data.now_clz %}
                        <div class="class-box">
                            <div class="class-up bg-info">
                                <p>当前课程：{{ data.now_clz.k_name }}</p>
                                <p>
                                    <span>老师：{{ data.now_clz.k_teacher }}</span>
                                    <span>时间：{{ data.now_clz.k_time }}</span>
                                </p>
                            </div>
                            <div class="class-down clearfix">
                                <p>作业提交期限: {{ data.now_clz.k_work_endtime }}</p>
                                <p data-id="{{ data.now_clz.id }}">
                                    <input class="hidden" type="file">
                                    {% if data.one_up %}
                                        <span id="up_work" class="btn btn-xs btn-info bg-info">交作业</span>
                                    {% else %}
                                        <span id="up_work" class="btn btn-xs btn-info bg-info">修改作业</span>
                                    {% endif %}
                                </p>
                                <div class="hidden" style="float: right; padding: 2px 5px;">
                                    <img class="" width="20" src="/static/images/loading.jpg" alt="上传中">
                                </div>
                            </div>
                            <div style="display: none;" class="class-work clearfix">
                                <h5>作业安排:</h5>
                                <div data-work="{{ data.now_clz.k_work }}"></div>
                            </div>
                        </div>
                    {% else %}
                        <div class="alert alert-xs label-info text-white ">
                            近期无课程安排
                        </div>
                    {% endif %}
                </div>
                <div class="col-lg-6 col-xs-12">
                     {% if data and data.next_clz %}
                        <div class="class-box">
                            <div class="class-up bg-warning">
                                <p>下次开课：{{ data.next_clz.k_name }}</p>
                                <p>
                                    <span>老师：{{ data.next_clz.k_teacher }}</span>
                                    <span>时间：{{ data.next_clz.k_time }}</span>
                                </p>
                            </div>
                        </div>
                    {% else %}
                        <div class="alert alert-xs label-warning text-white ">
                            无下次课程安排
                        </div>
                    {% endif %}
                </div>
                <div class="col-lg-12 col-xs-12">
                    <div class="panel panel-success">
                        <div class="panel-heading">
                            <div class="panel-title">个人信息</div>
                        </div>
                        <div class="panel-body">
                            <ul class="list-unstyled">
                                <li>姓名：{{ stu.stu_name }}</li>
                                <li>班级：{{ stu.stu_class }}</li>
                                <li>电话：{{ stu.stu_tel }}</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            {% include "sign.html" %}
        </div>
    </div>
</div>
<script src="/static/style/js/work_up.js"></script>
<script>
    var _can_upload = true;  // 是否可以点击上传
    (function () {
        var $divs = $('.class-work div');
        $.each($divs, function (k, v) {
            $(v).html($(v).data('work'));
            $(v).removeAttr('data-work');
        });
    })();

    $('.class-down').click(function () {
        $(this).next('div').toggle();
    });

    // 上传文件操作
    var $in = $('input[type="file"]');
    $('#up_work').click(function () {
        if (_can_upload) {
            $in.click();
        }
    });
    $in.change(function () {  // 上传文件
        var kid = $('.class-down > p[data-id]').data('id');
        var file = $in[0].files[0];
        fileUp(kid, {{ stu.id }}, file, function (data) {
            if (data.status) {
                alert('SUCCESS: ' + data.msg);
                $('#up_work').html('修改作业');
            } else {
                alert('UPWORK ERROR: ' + data.msg)
            }
        })
    });
</script>

</body>
</html>